package com.fates.ucenter.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.fates.common.lang.BlankUtils;
import com.fates.ucenter.common.BaseController;
import com.fates.ucenter.constant.ApiConstant;
import com.fates.ucenter.entity.po.User;
import com.fates.ucenter.result.BaseResponseInfo;
import com.fates.ucenter.result.ResultErrorCode;
import com.fates.ucenter.service.UserService;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @since 2017-09-07
 */
@Controller
@RequestMapping(ApiConstant.RMS_LOGIN)
public class LoginController extends BaseController {

	 @Autowired
	 private UserService userService;
	 
	/**
     * 登录请求
     */
    @ResponseBody
    @RequestMapping(value = "",method={ RequestMethod.POST })
    public BaseResponseInfo submitLogin(@RequestParam(value = "account") String account,
             						@RequestParam(value = "password") String password,
             						@RequestParam(value = "remember", required = false) String remember) throws Exception {
    	BaseResponseInfo info = new BaseResponseInfo();
    	List<User> users=userService.selectList(new EntityWrapper<User>().eq("account", account).and().eq("password", password));
        if (BlankUtils.isBlank(users)) {
        	info.code=ResultErrorCode.InternalError.getCode();
        	return info;
        }
        info.data=users;
        return info;
    }
}
